package com.type;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;

public class User extends Person {
	long facebookUserId;
	ArrayList<Friend> friendList = new ArrayList<Friend>();
	ArrayList<Activity> activityList = new ArrayList<Activity>();
	
	
	public User() {
		super();
	}

	public long getFacebookUserId() {
		return facebookUserId;
	}
	
	public ArrayList<Friend> getFriendList() {
		return friendList;
	}
	
	public void setFriendList(ArrayList<Friend> friendList) {
		this.friendList = friendList;
	}

	public ArrayList<Activity> getActivityList() {
		return activityList;
	}
	
	public void setActivityList(ArrayList<Activity> activityList) {
		this.activityList = activityList;
	}
	
	
	@Override
	public void send(DataOutputStream dos) throws IOException, InterruptedException {
		dos.writeLong(getPhoneNumber());
		dos.writeLong(facebookUserId);
		
		if(friendList.isEmpty())
			dos.writeInt(0);
		else {
			dos.writeInt(friendList.size());
			for(Friend friend : friendList)
				friend.send(dos);
		}
		
		if(activityList.isEmpty())
			dos.writeInt(0);
		else {
			dos.writeInt(activityList.size());
			for(Activity activity : activityList)
				activity.send(dos);
		}
	}

	@Override
	public void receive(DataInputStream dis) throws IOException, InterruptedException {
		setPhoneNumber(dis.readLong());
		facebookUserId = dis.readLong();
		
		int friendListSize = dis.readInt();
		if(friendListSize > 0) {
			friendList.clear();
			for (int i = 0; i < friendListSize; i++) {
				Friend friend = new Friend();
				friend.receive(dis);
				friendList.add(friend);
			}
		}
		
		int activityListSize = dis.readInt();
		if(activityListSize > 0) {
			activityList.clear();
			for (int i = 0; i < activityListSize; i++) {
				Activity activity = new Activity();
				activity.receive(dis);
				activityList.add(activity);
			}
		}
	}
}
